r, c = map(int, input().strip().split())
l = [[int(j) for j in input().strip().split()] for i in range(r)]
dx =  [1,-1,0,0]
dy =  [0,0,1,-1]
dp = [[0 for r in range(c)] for j in range(r)]

for i in range(r):
    for j in range(c):
        if (i == 0 and (j != 0 or j != c)):
            if l[i][j] <= l[i + 1][j] or l[i][j] <= l[i][j + 1] or l[i][j] <= l[i][j - 1]:
                dp[i][j] = 1
            else:
                dp[i][j] = max(l[i + 1][j], l[i][j + 1], l[i][j + 1]) + 1
